package com.cqu.hospitalsystem.controller;

import com.cqu.hospitalsystem.entity.IdRelation;
import com.cqu.hospitalsystem.service.IdRelationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("idRelation")
@Tag(name = "IdRelationController", description = "ID关系管理")
public class IdRelationController {
    /**
     * 服务对象
     */
    @Resource
    private IdRelationService idRelationService;

    /**
     * 分页查询
     *
     * @param idRelation 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @GetMapping
    @Operation(summary = "分页查询ID关系", description = "根据筛选条件和分页信息查询ID关系")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "查询成功"),
            @ApiResponse(responseCode = "400", description = "查询失败")
    })
    public ResponseEntity<Page<IdRelation>> queryByPage(IdRelation idRelation, PageRequest pageRequest) {
        return ResponseEntity.ok(this.idRelationService.queryByPage(idRelation, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @Operation(summary = "根据ID查询ID关系", description = "根据ID关系ID查询单个ID关系")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "查询成功"),
            @ApiResponse(responseCode = "404", description = "ID关系不存在")
    })
    public ResponseEntity<IdRelation> queryById(@PathVariable("id") @Parameter(description = "ID关系ID") Long id) {
        return ResponseEntity.ok(this.idRelationService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param idRelation 实体
     * @return 新增结果
     */
    @PostMapping
    @Operation(summary = "新增ID关系", description = "创建新的ID关系")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "201", description = "创建成功"),
            @ApiResponse(responseCode = "400", description = "创建失败")
    })
    public ResponseEntity<IdRelation> add(@RequestBody @Parameter(description = "ID关系对象") IdRelation idRelation) {
        return ResponseEntity.ok(this.idRelationService.insert(idRelation));
    }

    /**
     * 编辑数据
     *
     * @param idRelation 实体
     * @return 编辑结果
     */
    @PutMapping
    @Operation(summary = "编辑ID关系", description = "更新ID关系信息")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "更新成功"),
            @ApiResponse(responseCode = "400", description = "更新失败")
    })
    public ResponseEntity<IdRelation> edit(@RequestBody @Parameter(description = "ID关系对象") IdRelation idRelation) {
        return ResponseEntity.ok(this.idRelationService.update(idRelation));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    @Operation(summary = "删除ID关系", description = "根据ID关系ID删除ID关系")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "删除成功"),
            @ApiResponse(responseCode = "400", description = "删除失败")
    })
    public ResponseEntity<Boolean> deleteById(@Parameter(description = "ID关系ID") Long id) {
        return ResponseEntity.ok(this.idRelationService.deleteById(id));
    }
}